package com.itheima.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.common.entity.PageResult;
import com.itheima.common.entity.QueryPageBean;
import com.itheima.mapper.CheckItemMapper;
import com.itheima.pojo.CheckItem;
import com.itheima.service.CheckItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CheckItemServiceImpl  implements CheckItemService {
    @Autowired
   private CheckItemMapper checkItemMapper;

    /**
     * 查询所有检查项
     * @return
     */
    public List<CheckItem> findAll() {
        return checkItemMapper.findAll();
    }

    /**
     * 通过id查询检查项
     * @param id
     * @return
     */
    public CheckItem findById(Integer id) {
        return checkItemMapper.findById(id);
    }

    /**
     * 根据检查组id查询关联的检查项id
     * @param id
     * @return
     */
    public List<Integer> findCheckItemIdsByCheckGroupId(Integer id) {
        return checkItemMapper.findCheckItemIdsByCheckGroupId(id);
    }
    /**
     * 根据id删除检查项
     * @param id
     * @return
     */
    public Boolean delete(Integer id) {
        return checkItemMapper.delete(id);
    }

    /**
     * 新增
     * @param checkItem
     * @return
     */
    public boolean add(CheckItem checkItem) {
        return checkItemMapper.add(checkItem);
    }

    /**
     * 编辑
     * @param checkItem
     * @return
     */
    public boolean edit(CheckItem checkItem) {
        return checkItemMapper.edit(checkItem);
    }
    /**
     * 分页查询
     * @param queryPageBean
     * @return
     */
    public PageResult findPage(QueryPageBean queryPageBean) {
        PageHelper.startPage(queryPageBean.getCurrentPage(),queryPageBean.getPageSize());
        Page<CheckItem> page = (Page<CheckItem>) checkItemMapper.findAll();
        return new PageResult(page.getTotal(),page.getResult());
    }
}
